import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
import Login from './components/Login.vue'
import Register from './components/Register.vue'
import Home from './components/Home.vue'
import Freeback from './components/Freeback.vue'
import Personal from './components/Personal.vue'
import MyOrder from './components/personal/MyOrder.vue'
import MyAddress from './components/personal/MyAddress.vue'
import AddAddress from './components/personal/AddAddress.vue'
import MyShoppingCart from './components/personal/MyShoppingCart.vue'
import Order from './components/Order.vue'
import CateBook from './components/catebook/CateBook.vue'
import GoodDetail from './components/goods/GoodDetail.vue'
import AllGoods from './components/goods/AllGoods.vue'
import SearchGoods from './components/goods/SearchGoods.vue'
import Pay from './components/Pay.vue'



const router = new VueRouter({
    routes: [
        {
            path: '/',
            redirect: '/login'
        },
        { path: '/login', component: Login },
        { path: '/register', component: Register },
        {
            path: '/home', component: Home,
            children: [
                {
                    path: '/catebook',
                    name: 'CateBook',
                    component: CateBook,
                }
            ]
        },
        { path: '/allgoods', name: 'allgoods', component: AllGoods},
        { path: '/gooddetail/:id', name: 'gooddetail', component: GoodDetail ,props:true},
        { path: '/freeback', component: Freeback },
        {
            path: '/personal', // 主页
            name: 'Personal',
            component: Personal,
            children: [
                {
                    path: '/',
                    name: 'HomeIndex',
                    component: MyOrder
                },
                {
                    path: 'myAddress',
                    name: 'MyAddress',
                    component: MyAddress
                },
                {
                    path: 'addAddress',
                    name: 'AddAddress',
                    component: AddAddress
                },
                {
                    path: 'myOrder',
                    name: 'MyOrder',
                    component: MyOrder
                },
                {
                    path: 'myShoppingCart',
                    name: 'MyShoppingCart',
                    component: MyShoppingCart
                }
            ]
        },
        { path: '/order', component: Order },
        // { path: '/catebook', component: CateBook },
        { path: '/orderpay', component: Order },
        { path: '/searchgoods', component: SearchGoods },
        { path: '/pay', component: Pay },
        
    ]
})

// //为路由对象，添加beforeEach 导航守卫
// router.beforeEach((to, from, next) => {
//     /* /*   to 将要访问的路径
//       from 代表从哪个路径跳转而来
//       next 是一个函数，表示放行 
//       next() 放行    next('/login)
//        * / */
//     if (to.path === '/login') return next();
//     const tokenStr = window.sessionStorage.getItem('token')
//     if (!tokenStr) return next('/login')
//     else next()
// })
export default router
